package com.og.ouroa.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.og.ouroa.common.annotations.EnableLoginHandle;
import com.og.ouroa.common.exception.BusinessException;
import com.og.ouroa.common.result.R;
import com.og.ouroa.common.result.ResponseEnum;
import com.og.ouroa.pojo.entity.CourseBoard;
import com.og.ouroa.pojo.entity.UserInfo;
import com.og.ouroa.pojo.vo.CourseVO;
import com.og.ouroa.service.CourseBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Us
 * @since 2021-12-13
 */
@CrossOrigin
@RestController
@RequestMapping("/admin/courseBoard")
@Api(tags = "留言板接口")
public class CourseBoardController {

    @Autowired
    CourseBoardService service;

    @EnableLoginHandle
    @ApiOperation("添加留言")
    @PostMapping("/addBoard")
    public R getByCnumber( @ApiParam(value = "留言信息" ) @RequestBody CourseBoard board){

        service.addBoard(board);
        return  R.ok().message("添加成功");
    }

    @EnableLoginHandle
    @ApiOperation("删除留言")
    @DeleteMapping("/removeBoard/{bid}")
    public R removeBoard( @ApiParam(value = "留言id" ) @PathVariable Integer bid){


        service.removeBoard(bid);
        return  R.ok().message("删除成功");
    }

    @EnableLoginHandle
    @ApiOperation("获取留言")
    @GetMapping("/getBoard/{page}/{limit}/{cid}/{pid}")
    public R getBoard(             @ApiParam(value = "当前页码", required = true) @PathVariable Long page,
                                   @ApiParam(value = "每页记录数", required = true) @PathVariable Long limit,
                                   @ApiParam(value = "课程id", required = true) @PathVariable Integer cid,
                                   @ApiParam(value = "父级id(为空填充0)") @PathVariable Integer pid
                                   ){


        Page<CourseBoard> pages = new Page<>(page,limit);

        IPage<CourseBoard> bycid = service.getBycid(pages, cid, pid);


        return  R.ok().message("获取成功").data("page",bycid);
    }




}

